home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / www / HTTX.lha / AWeb / HTTXPluginPRT.awebrx < prev   
Text File  |  1997-07-16  |  4KB  |  197 lines

  1. /*
  2.     Print current document as TEXT using HTTX
  3.     $VER: HTTXPluginPRT 2.0 (1.5.97) by Gabriele Favrin (favrin@tin.it)
  4. */
  5.  
  6. Options Results
  7. Options failat 999
  8.  
  9. Parse ARG mode mode_data .
  10.  
  11. 'GetCFG TEMPPATH VAR' prefs_temppath
  12.  
  13. req_title = '"Print as text"'
  14. temp_out     = prefs_temppath"temp_HTTXP_Output.txt"
  15. temp_name = prefs_temppath"temp_HTTXP_file"
  16. eol         = '0A'x
  17. trg         = ""
  18. del_list     = prefs_temppath"temp_HTTXP_#?"
  19. force         = ""
  20. string     = "HTTXPlugin V2.0"||eol||eol
  21. option     = ""
  22.  
  23. prefs_info     = 0
  24. prefs_report = 1
  25.  
  26. Call readcfg()
  27.  
  28. If (mode == "TARGET") then
  29.     trg="TARGET" mode_data
  30.  
  31. 'Get URL VAR' doc_url trg
  32. org_url=doc_url
  33.  
  34. 'GetCFG HTMLMODE'
  35. If result == 0 then
  36.     frms.0=0
  37. else
  38.     'Get FRAMES ALL' trg 'STEM' frms
  39.  
  40. If (frms.0 = 0) then do
  41.     Call SaveHTML()
  42.     Call Convert()
  43.     Call CleanUp()
  44. End
  45. else do
  46.     prefs_report=0
  47.  
  48.     'Request' req_title '"Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"'
  49.     If rc == 5 then exit()
  50.     option=result
  51.  
  52.     do ct=1 for frms.0
  53.         doc_url=frms.ct.url
  54.         trg="TARGET="frms.ct.id
  55.  
  56.         If option == 1 then do
  57.             If ct > 1 then do
  58.                 string=eol||eol||"----"||eol||eol
  59.             End
  60.  
  61.             Call SaveHTML()
  62.             Call Convert()
  63.             Call CleanUp()
  64.         End
  65.         else do
  66.             'Open "'frms.ct.url'"'
  67.             'Wait "'frms.ct.url'"'
  68.  
  69.             'Request' req_title '"Convert this frame?" _Yes|_No|_Cancel'
  70.             If rc == 5 then do
  71.                 Call CleanUp()
  72.                 'Open "'org_url'"'
  73.                 exit()
  74.             End
  75.  
  76.             If result == 1 then do
  77.                 trg=""
  78.                 string = "HTTXPlugin V2.0"||eol||eol
  79.  
  80.                 Call SaveHTML()
  81.                 Call Convert()
  82.                 Call CleanUp()
  83.             End
  84.         End
  85.     End
  86.  
  87.     If option == 1 then do
  88.         Call displayOutput()
  89.         Call CleanUp()
  90.     End
  91.     else do
  92.         If option == 2 then do
  93.             'Open "'org_url'"'
  94.         End
  95.     End
  96. End
  97.  
  98. exit 0
  99.  
  100.  
  101. CleanUp:
  102.     address command 'C:Delete >NIL: QUIET' del_list
  103.     return
  104.  
  105.  
  106. SaveHTML:
  107.     'SaveAs "'temp_name'" NOICON' trg
  108.     If rc ~= 0 then do
  109.         'Request req_title "Error while saving HTML on temporary path*N *N'prefs_temppath'" _Ops'
  110.         exit 0
  111.     End
  112.     return
  113.  
  114.  
  115. convert:
  116.     'Get MIME VAR' mtype trg
  117.     If (Upper(mtype) == "TEXT/HTML") then
  118.         drop force
  119.     else
  120.         force=""
  121.  
  122.     Call PrepareFile()
  123.  
  124.     res=httx()
  125.     If (res == 212) then do
  126.         'Request 'req_title' "File is not html! Print anyway?" "_Print|_Cancel"'
  127.  
  128.         If (rc ~= 5) then do
  129.             address command 'C:Copy "'temp_name'" "PRT:"'
  130.             prefs_report=0
  131.             res=0
  132.             Call displayOutput()
  133.         End
  134.     End
  135.     else do
  136.         If option == "" then do
  137.             Call displayOutput()
  138.         End
  139.     End
  140.     return
  141.  
  142.  
  143. httx:
  144.     address command 'plugins/httx/HTTX >'temp_out' "'temp_name'" PRINT CFG=HTTXprt.prefs' force
  145.     return rc
  146.  
  147.  
  148. displayOutput:
  149.     If (prefs_report == 1) then do
  150.         'Open "file://localhost/'temp_out'" RELOAD'
  151.         'Wait "file://localhost/'temp_out'"'
  152.     End
  153.     else do
  154.         If (res == 0) then do
  155.             'Request 'req_title' "File printed" _Ok! NOWAIT'
  156.         End
  157.         else do
  158.             'Request 'req_title' "Error 'rc'" _Ok! NOWAIT'
  159.         End
  160.     End
  161.     return
  162.  
  163.  
  164. PrepareFile:
  165.     If Open(fp, "PRT:", 'W') then do
  166.         If (prefs_info == 1) then do
  167.             'Get INFO STEM' infos trg
  168.             If (infos.0 > 0) then do
  169.                 string=string||eol||"Header:"||eol
  170.  
  171.                 do ctx=1 for infos.0
  172.                     If (infos.ctx.type ~= "CACHE") then do
  173.                         string=string||infos.ctx.value||eol
  174.                         If infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url
  175.                     End
  176.                 End
  177.             End
  178.         End
  179.  
  180.         WriteCH(fp, string)
  181.         Call Close(fp)
  182.     End
  183.     return
  184.  
  185.  
  186. readcfg:
  187.     If Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do
  188.         cfg=ReadLN(rcfg_fp)
  189.  
  190.         If Left(cfg, 6) == "prefs_" then do
  191.             interpret translate(strip(cfg), ';',' ')
  192.             prefs_savedir=Translate(prefs_savedir, ' ', ';')
  193.         End
  194.  
  195.         Call Close(rcfg_fp)
  196.     End
  197.